from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from apps.pcb.models import *


# Register your models here.

# class PcbInventoryInline(admin.TabularInline):
#     model = PcbInventory
#     extra = 1
#     style = 'table'  # 列表显示，one：只显示一条  accordion：缩略列表显示，可下拉  tab：横向tab显示 stacked：块显示 table：列表


class PcbTagAdmin(ImportExportModelAdmin):
    list_display = ('name', 'date_joined')
    list_filter = ['date_joined']
    list_per_page = 10
    search_fields = ['name']
    sortable_by = ['date_joined']


class PcbCreateCompanyAdmin(ImportExportModelAdmin):
    list_display = ('name', 'show_image', 'telephone', 'address', 'date_joined', 'desc')
    list_filter = ['date_joined']
    list_per_page = 10
    search_fields = ['name']
    sortable_by = ['date_joined']


class PcbCreateSoftwareAdmin(ImportExportModelAdmin):
    list_display = ('name', 'show_image', 'date_joined')
    list_filter = ['date_joined']
    list_per_page = 10
    search_fields = ['name']
    sortable_by = ['date_joined']


class PcbCreateSoftwareVersionAdmin(ImportExportModelAdmin):
    list_display = ('show_software_image', 'name', 'date_joined')
    list_filter = ['software__name', 'date_joined']
    list_per_page = 10
    # search_fields = ['name']
    sortable_by = ['date_joined']


class PcbAuthorAdmin(ImportExportModelAdmin):
    list_display = ('name', 'show_image', 'date_joined')
    list_filter = ['date_joined']
    list_per_page = 10
    search_fields = ['name']
    sortable_by = ['date_joined']


class PcbAdmin(ImportExportModelAdmin):
    list_display = ('my_id', 'show_image', 'show_author_image', 'show_software_image',
                    'show_company_image', 'stock', 'desc', 'date_joined', 'date_tested', 'is_active')
    list_filter = ['author__name', 'create_software_version__software__name', 'create_company', 'tag',
                   'date_joined', 'is_active']
    list_display_links = ['show_image']
    list_per_page = 20
    search_fields = ['my_id']
    sortable_by = ['date_joined', 'money', 'date_tested']
    radio_fields = {"create_software_version": admin.HORIZONTAL,
                    "create_company": admin.HORIZONTAL, }
    # inlines = [PcbInventoryInline]


admin.site.register(PcbTag, PcbTagAdmin)
admin.site.register(PcbCreateCompany, PcbCreateCompanyAdmin)
admin.site.register(PcbCreateSoftware, PcbCreateSoftwareAdmin)
admin.site.register(PcbCreateSoftwareVersion, PcbCreateSoftwareVersionAdmin)
admin.site.register(PcbAuthor, PcbAuthorAdmin)
admin.site.register(Pcb, PcbAdmin)
